Implement copying from a window, part of bug #348493.
authorRichard Hult <richard@imendio.com>
Fri, 25 May 2007 19:47:23 +0000 (19:47 +0000)
committerRichard Hult <rhult@src.gnome.org>
Fri, 25 May 2007 19:47:23 +0000 (19:47 +0000)
2007-05-25  Richard Hult  <richard@imendio.com>

* gdk/quartz/gdkimage-quartz.c: (_gdk_quartz_image_copy_to_image):
Implement copying from a window, part of bug #348493.

svn path=/trunk/; revision=17917

ChangeLog
gdk/quartz/gdkimage-quartz.c

index d9f2ca9dd1c1cd8210aa5e58d52b4e10bbd0629c..ccd0ac8b903f041d49cf1495fef9887d33ae14c6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-05-25  Richard Hult  <richard@imendio.com>
+
+       * gdk/quartz/gdkimage-quartz.c: (_gdk_quartz_image_copy_to_image):
+       Implement copying from a window, part of bug #348493.
+
 2007-05-25  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkprintoperation-unix.c (unix_end_run): Hold a 
index 40c421bed24c65946860dcdf8c219dad6b39e31a..ed10d8abc8685624ceacacb055a61856931c4892 100644 (file)
@@ -36,8 +36,67 @@ _gdk_quartz_image_copy_to_image (GdkDrawable *drawable,
                                 gint         width,
                                 gint         height)
 {
-  /* FIXME: Implement */
-  return NULL;
+  GdkScreen *screen;
+  
+  g_return_val_if_fail (GDK_IS_DRAWABLE_IMPL_QUARTZ (drawable), NULL);
+  g_return_val_if_fail (image != NULL || (dest_x == 0 && dest_y == 0), NULL);
+
+  screen = gdk_drawable_get_screen (drawable);
+  if (!image)
+    image = _gdk_image_new_for_depth (screen, GDK_IMAGE_FASTEST, NULL, 
+                                     width, height,
+                                     gdk_drawable_get_depth (drawable));
+  
+  if (GDK_IS_PIXMAP_IMPL_QUARTZ (drawable))
+    {
+      g_warning ("Copying a pixmap to an image is not implemented yet.");
+    }
+  else if (GDK_IS_WINDOW_IMPL_QUARTZ (drawable))
+    {
+      GdkQuartzView *view;
+      NSBitmapImageRep *rep;
+      NSRect rect;
+      guchar *data;
+      int x, y;
+      NSSize size;
+
+      view = GDK_WINDOW_IMPL_QUARTZ (drawable)->view;
+
+      /* We return the image even if we can't copy to it. */
+      if (![view lockFocusIfCanDraw])
+        return image;
+
+      rect = NSMakeRect (src_x, src_y, width, height);
+
+      rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect: rect];
+      [view unlockFocus];
+         
+      data = [rep bitmapData];
+      size = [rep size];
+
+      for (y = 0; y < size.height; y++)
+       {
+         guchar *src = data + y * [rep bytesPerRow];
+
+         for (x = 0; x < size.width; x++)
+           {
+             gint32 pixel;
+
+             if (image->byte_order == GDK_LSB_FIRST)
+               pixel = src[0] << 8 | src[1] << 16 |src[2] << 24;
+             else
+               pixel = src[0] << 16 | src[1] << 8 |src[2];
+
+             src += 3;
+
+             gdk_image_put_pixel (image, dest_x + x, dest_y + y, pixel);
+           }
+       }
+
+      [rep release];
+    }
+
+  return image;
 }
 
 static void